package com.spzx.product.api.factory;


import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteProductService;
import com.spzx.product.api.vo.ProductSkuVo;
import com.spzx.product.api.vo.SkuPriceVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;

/**
 * 远程商品服务降级处理类
 */
//@Component
@Slf4j
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService> {

    @Override
    public RemoteProductService create(Throwable throwable) {

        log.error("商品服务调用失败:{}", throwable.getMessage());

//        return (skuId, source) -> R.fail("远程服务调用失败" + throwable.getMessage());
        return new RemoteProductService() {
            @Override
            public R<ProductSkuVo> getProductVoSku(Long skuId, String source) {
                return R.fail("获取商品详情失败 : " + throwable.getMessage());
            }

            @Override
            public R<SkuPriceVo> getSkuPrice(Long skuId, String source) {
                return R.fail("获取商品sku价格失败 : " + throwable.getMessage());
            }

            @Override
            public R<List<SkuPriceVo>> getSkuPriceList(List<Long> skuIdList, String source) {
                return R.fail("获取商品sku价格列表失败 : " + throwable.getMessage());
            }

        };

    }

}
